// 字段类型枚举
public enum FieldType : byte
{
    Bool = 0,
    Int = 1,
    Float = 2,
    // 可以继续扩展其他类型
}

// 字段数据接口 - 避免装箱拆箱
public interface IFieldData
{
    FieldType Type { get; }
    void SetValue(object value);
    object GetValue();
    IFieldData Clone();
    
    public static IFieldData CreateFieldData(FieldType type, string val)
    {
        return type switch
        {
            FieldType.Bool => new BoolFieldData { Value = bool.TryParse(val, out bool result) && result },
            FieldType.Int => new IntFieldData { Value = int.TryParse(val, out int result) ? result : 0 },
            FieldType.Float => new FloatFieldData { Value = float.TryParse(val, out float result) ? result : 0f },
        };
    }
}

// 泛型字段数据基类
public abstract class FieldData<T> : IFieldData
{
    public T Value;
    public abstract FieldType Type { get; }
    
    public void SetValue(object value) => Value = (T)value;
    public object GetValue() => Value;
    
    public abstract IFieldData Clone();
}

public static class FieldDataEx
{
    public static bool TryGetValue<T>(this IFieldData fieldData, out T value)
    {
        if (fieldData is FieldData<T> fd)
        {
            value = fd.Value;
            return true;
        }
        value = default;
        return false;
    }
}